package com.weibo.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.weibo.dao.IWeiboDao;
import com.weibo.pojo.Tcomment;
import com.weibo.pojo.Tweibo;
import com.weibo.service.IWeiboService;


public class WeiboServiceImpl implements IWeiboService {

	IWeiboDao weiboDao;

	@Override
	public List<Tweibo> getHomeWeiboList(Integer userId) throws Exception {
		return weiboDao.getHomeWeiboList(userId);
	}

	public IWeiboDao getWeiboDao() {
		return weiboDao;
	}

	public void setWeiboDao(IWeiboDao weiboDao) {
		this.weiboDao = weiboDao;
	}

	@Override
	public void saveWeibo(Tweibo weibo) throws Exception {
		weiboDao.saveWeibo(weibo);
	}

	@Override
	public Map<Integer, List<Tcomment>> getCommentMap(List<Tweibo> weiboList)
			throws Exception {
		Map<Integer, List<Tcomment>> commentMap = new HashMap<Integer, List<Tcomment>>();
		for (Tweibo weibo : weiboList) {
			List<Tcomment> commentList = weiboDao.getCommentListByWeibo(weibo
					.getWeiboId());
			commentMap.put(weibo.getWeiboId(), commentList);
		}
		System.out.println(commentMap);
		System.out.println(weiboList);
		return commentMap;
	}

	@Override
	public Tweibo getWeiboById(Integer weiboId) {
		return weiboDao.getWeiboById(weiboId);
	}

	@Override
	public void deleteWeibo(Tweibo weibo) {
		weiboDao.deleteWeibo(weibo);
		
	}

}
